<template>
  <header class="dashboard-header">
    <div class="header-left">
      <div class="logo"><img src="/src/static/guet_logo_round.jpg" /></div>
      <h1 class="dashboard-title">社团管理系统</h1>
    </div>
    <div class="header-center">
      <div class="nav-item" :class="{ active: currentRoute === '/dashboard/home' }" @click="navigateTo('/dashboard/home')">首页</div>
      <div class="nav-item" :class="{ active: currentRoute === '/dashboard/join-club' }" @click="navigateTo('/dashboard/join-club')">加入社团</div>
      <div class="nav-item" :class="{ active: currentRoute === '/dashboard/activity-center' }" @click="navigateTo('/dashboard/activity-center')">活动中心</div>
      <div class="nav-item" :class="{ active: currentRoute === '/dashboard/clubs' }" @click="navigateTo('/dashboard/clubs')">我的社团</div>
    </div>
    <!-- 搜索框 -->
    <div class="search-box">
      <input type="text" placeholder="搜索社团或活动..." class="search-input">
      <span class="search-icon">🔍</span>
    </div>
    <div class="header-right">
      <!-- 消息通知 -->
      <div class="message-icon" @click="onMessageClick">
         <span class="email-icon" @click="onUserClick">📧</span>
        <span class="message-badge" v-if="unreadMessages > 0">{{ unreadMessages }}</span>
      </div>
      
      <!-- 我加入的社团
      <div class="my-societies" @click="onSocietiesClick">
        <span class="text">{{ joinedSocietiesCount }}个社团</span>
      </div> -->
      

      
      <!-- 用户信息 -->
      <div class="user-info">
        <span class="user-icon" @click="onUserClick"><img src="/src/static/logo.jpg" /></span>
      </div>
      
      <!-- 退出登录按钮 -->
      <button @click="onLogout" class="logout-button">退出登录</button>
    </div>
  </header>
</template>

<script setup>
import { computed } from 'vue'
import { useRouter } from 'vue-router'
import { store } from '../store/index.js'

const router = useRouter()
const currentRoute = computed(() => router.currentRoute.value.fullPath)

// 导航方法
const navigateTo = (path) => {
  router.push(path)
}

// Props
const props = defineProps({
  currentUser: {
    type: Object,
    default: null
  },
  unreadMessages: {
    type: Number,
    default: 0
  },
  joinedSocietiesCount: {
    type: Number,
    default: 0
  }
})

// Emits
const emit = defineEmits(['message-click', 'societies-click', 'user-click', 'logout'])



// 事件处理函数
const onMessageClick = () => {
  emit('message-click')
}

const onSocietiesClick = () => {
  emit('societies-click')
}

const onUserClick = () => {
  emit('user-click')
}

const onLogout = () => {
  emit('logout')
}
</script>

<style scoped>
/* 顶部导航栏 */
.dashboard-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 24px;
  height: 64px;
  background-color: white;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  z-index: 100;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

.logo {
  width: 64px;
  height: 64px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.3s;
}

.logo:hover {
  transform: scale(1.1) rotate(5deg);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.logo img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 8px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.dashboard-title {
  font-size: 20px;
  font-weight: 600;
  color: #333;
}

.header-center {
  display: flex;
  align-items: center;
  gap: 48px;
}

.nav-item {
  font-size: 16px;
  font-weight: 500;
  color: #666;
  cursor: pointer;
  transition: color 0.3s;
  padding: 8px 12px;
  border-radius: 4px;
}

.nav-item:hover {
  color: #1890ff;
  background-color: #f0f2f5;
}

.nav-item.active {
  color: #1890ff;
  background-color: #e6f7ff;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 20px;
}

/* 搜索框 */
.search-box {
  display: flex;
  align-items: center;
  position: relative;
  width: 280px;
}

.search-input {
  width: 100%;
  padding: 8px 32px 8px 12px;
  border: 1px solid #e8e8e8;
  border-radius: 20px;
  font-size: 14px;
  outline: none;
  transition: all 0.3s;
}

.search-input:focus {
  border-color: #1890ff;
  box-shadow: 0 0 0 2px rgba(24, 144, 255, 0.1);
}

.search-icon {
  position: absolute;
  right: 12px;
  color: #999;
  font-size: 16px;
  pointer-events: none;
}

/* 消息图标 */
.message-icon {
  position: relative;
  cursor: pointer;
  font-size: 20px;
  padding: 8px;
  border-radius: 4px;
  transition: background-color 0.3s;
}

.message-icon:hover {
  background-color: #f0f2f5;
}

.message-badge {
  position: absolute;
  top: 0;
  right: 0;
  background-color: #ff4d4f;
  color: white;
  font-size: 10px;
  padding: 2px 6px;
  border-radius: 10px;
  min-width: 16px;
  text-align: center;
}


/* 用户信息 */
.user-info {
  display: flex;
  align-items: center;
}

.user-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 48px;
  height: 48px;
  padding: 4px;
  cursor: pointer;
  border-radius: 4px;
  transition: background-color 0.3s;
  box-sizing: border-box;
}

.user-icon:hover {
  background-color: #f0f2f5;
}

.user-icon img {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  object-fit: cover;
}

.email-icon {
  font-size: 24px;
  color: #666;
  cursor: pointer;
  transition: color 0.3s, background-color 0.3s;
  padding: 8px;
  border-radius: 4px;
}

.email-icon:hover {
  color: #1890ff;
  background-color: #f0f2f5;
}

.logout-button {
  padding: 6px 16px;
  background-color: #f56c6c;
  color: white;
  border: none;
  border-radius: 4px;
  font-size: 14px;
  cursor: pointer;
  transition: background-color 0.3s, transform 0.1s;
}

.logout-button:hover {
  background-color: #e64e4e;
}

.logout-button:active {
  transform: scale(0.98);
}

/* 响应式设计 */
@media (max-width: 768px) {
  .dashboard-header {
    padding: 0 16px;
  }
  
  .dashboard-title {
    font-size: 18px;
  }
}
</style>